#ifndef __OS_SPEC_H__
#define __OS_SPEC_H__

#define SEM_WAIT_INFINITE ((unsigned int)(-1))
#include <assert.h>
#ifdef WIN32 
// 	#include <windows.h>
 //	#include <winsock2.h>
	#include <stdio.h>
	#include <string.h>
	#include <stdlib.h>
 	#include <time.h>
    #define THREAD_START  unsigned long  
//##ModelId=47847193001F
	typedef unsigned long  (*THREADFUNC)(void* lparam);
//##ModelId=478471930021
	typedef void*	HANDLE;
//##ModelId=47847193002E
	typedef HANDLE	pthread_t;
//##ModelId=478471930030
	typedef HANDLE	psem_t;
//##ModelId=478471930032
	typedef HANDLE  TSem_t;
//##ModelId=47847193003E
	typedef HANDLE	pthread_mutex_t;
#define OS_THREAD_PRIORITY_NORMAL			  (0)
#define OS_THREAD_STACK_NORMAL               (0)		
#else
	#include <unistd.h>
	#include <stdio.h>
	#include <string.h>
	#include <stdlib.h>
	#include <pthread.h>
	#include <sys/time.h>
        #include <errno.h>
        #include <netdb.h>
        #include <sys/socket.h>
        #include <sys/types.h>
        #include <arpa/inet.h>
        #include <netinet/in.h>
#define THREAD_START void*
	typedef THREAD_START (*THREADFUNC)(void* lParam);
	typedef int		SOCKET;
	typedef struct _tagTPSem_t
	{
		pthread_cond_t		tCond;
		int					nCount;
		pthread_mutex_t		tMutex;
	}TSem_t,*psem_t;

#define OS_THREAD_PRIORITY_NORMAL                         (9)
#define OS_THREAD_STACK_NORMAL                            (10*1024)

#ifndef INVALID_SOCKET
#define INVALID_SOCKET                                    (-1)
#endif
		
#endif

#ifdef __cplusplus
	extern "C" {
#endif

int		OS_Init();
void	OS_UnInit();

psem_t	OS_SemCreate(int nval);
void	OS_SemDestroy(psem_t pSem);
void	OS_SemSignal(psem_t pSem);
/*0,suc, or time-out*/
int		OS_SemWait(psem_t pSem,unsigned int	nWaitMinisecs);

pthread_t OS_ThreadCreate(THREADFUNC pFunc,int nPrio,int nStackSize,void* lparam);
void	OS_ThreadJoin(pthread_t tThread);
void	OS_ThreadCancel(pthread_t tThread);
void	OS_ThreadDestroy(pthread_t tThread);


void	OS_Sleep(unsigned long dwSecs);
void    OS_USleep(unsigned int nMiniSecs);

#ifdef __cplusplus
	}
#endif

#endif

